package com.manli.api.controller;

import java.util.Arrays;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.manli.api.pojo.QueryParamsPartner;
import com.manli.api.pojo.Result;
import com.manli.api.pojo.SessionInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.manli.api.base.annotation.Permissions;
import com.manli.api.dto.Partner;
import com.manli.api.service.PartnerService;
import com.manli.api.util.SessionInfoUtils;



/**
 * 
 *
 * @author manli
 * @email 
 * @date 2020-04-29 10:07:53
 */
@Api(value="/partner", tags="分店机构")
@RestController
@RequestMapping("api/partner")
public class PartnerController {
    @Autowired
    private PartnerService partnerService;
    @Autowired
    private SessionInfoUtils sessionInfoUtils;
    /**
     * 列表
     */
    @ApiOperation(value = "列表",notes = "")
    @PostMapping("/list")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result list(@RequestBody QueryParamsPartner params,HttpServletRequest request){
        return partnerService.queryPage(params,request);
    }

    /**
     * 全部数据信息
     */
    @ApiOperation(value = "全部数据信息",notes = "")
    @PostMapping("/all")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result all(@RequestBody QueryParamsPartner params,HttpServletRequest request){
        return partnerService.queryAll(params,request);
    }

    /**
     * 根据主店id获取所有分店全部数据信息
     */
    @ApiOperation(value = "根据主店id获取所有分店全部数据信息",notes = "")
    @PostMapping("/getPartnersByBrandhId")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result getPartnersByBrandhId(@RequestBody QueryParamsPartner params,HttpServletRequest request){
        return partnerService.queryAll1(params,request);
    }

    /**
     * 单条信息
     */
    @ApiOperation(value = "单条信息",notes = "单条信息")
    @GetMapping("/info/{partnerId}")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result info(@PathVariable("partnerId") Integer partnerId){
        return partnerService.getById(partnerId);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存",notes = "保存")
    @PostMapping("/save")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result save(@RequestBody Partner partner , HttpServletRequest request){
    	SessionInfo sessionInfo = sessionInfoUtils.getSessionInfoByAuth(request);
        return partnerService.save(partner,sessionInfo);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改",notes = "修改")
    @PostMapping("/update")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result update(@RequestBody Partner partner){
        return partnerService.updateById(partner);
    }

    /**
     * 删除单条数据
     */
    @ApiOperation(value = "删除",notes = "删除")
    @ApiImplicitParam(name = "partnerIds", value = "id",dataType = "int", required = true)
    @PostMapping("/delete")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result delete(Integer partnerId){
        return partnerService.removeById(partnerId);
    }

    /**
     * 删除多条数据
     */
    @ApiOperation(value = "删除",notes = "删除")
    @ApiImplicitParam(name = "partnerIds", value = "id数组,json字符串",dataType = "id数组,json字符串", required = true)
    @PostMapping("/deleteIds")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN_PERMISSONS)
    public Result deleteIds(@RequestBody Integer[] partnerIds){
        return partnerService.removeByIds(Arrays.asList(partnerIds));
    }

}
